<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加订单</title>
    <link rel="stylesheet" href="../lib/layui-v2.5.4/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body>

<form class="layui-form" >
    <div class="layui-form-item ">

        <label class="layui-form-label">部门名称</label>
        <div class="layui-input-inline ">
            <select id="part2" name="part2" lay-filter="partFilter2" class="layui-input layui-unselect">
                <option value="">--请选择--</option>
            </select>
        </div>

        <div class="layui-form-label">员工名称</div>
        <div class="layui-input-inline  ">
            <select id="emp2" name="emp2" lay-filter="empFilter2">
                <option value="">--请选择--</option>
            </select>
        </div>

        <div class="layui-form-label">客户姓名</div>
        <div class="layui-input-inline ">
            <select id="client2" name="client2" lay-filter="clientFilter2">
                <option value="">--请选择--</option>
            </select>
        </div>
    </div>
</form>
<script src="../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="../lib/layui-v2.5.4/layui.js" charset="utf-8"></script>
<!--<script src="../js/order-manage.js" charset="utf-8"></script>-->
<script>

    layui.use(['form', 'table', 'layer'], function () {
        let $ = layui.jquery,
            form = layui.form,
            layer = layui.layer;




            //初始化部门名称数据
            $.get({
                url: "/api/department/partList", success: (resp) => {
                    resp.forEach(r => {
                        $("#part2").append("<option value='" + r.pid + "'>" + r.pname + "</option>");
                    });
                    form.render('select');
                }, dataType: "json"
            });



        //部门名称select监听器
    form.on('select(partFilter2)', (data) => {
        //部门id
        let pid = $('#part2 option:selected').val();
        if (!!pid) {
            $('.e-class').remove();
            $('.c-class').remove();
            $.get({
                url: "/api/emp/" + pid + "", success: (resp) => {
                    resp.forEach(r => {
                        $("#emp2").append("<option class='e-class' value='" + r.eid + "'>" + r.etruename + "</option>");
                    });
                    form.render('select');
                }, dataType: "json"
            });

        }
    });

    //员工名称select监听器
    form.on('select(empFilter2)', (data) => {
        //员工id
        let eid = $('#emp2 option:selected').val();
        let pid = $('#part2 option:selected').val();
        //根据员工id查询客户列表
        if (!!eid) {
            $('.c-class').remove();
            $.get({
                url: "/api/Client/" + eid, success: (resp) => {
                    resp.forEach(r => {
                        $("#client2").append("<option class='c-class' value='" + r.cid + "'>" + r.cname + "</option>");
                    });
                    form.render('select');
                }, dataType: "json"
            });

        }
    });


    form.on('select(clientFilter2)', (data) => {
        //员工id
        let cid = $('#client2 option:selected').val();
        let eid = $('#emp2 option:selected').val();
        let pid = $('#part2 option:selected').val();
        //根据乘客和id查询客户列表
        form.render('select');
    });

    })

    //   getValue属于window对象
    function getValue() {
        let eid = $('#emp2 option:selected').val();
        let cid = $('#client2 option:selected').val();

        var data = {"eid": eid, "cid":cid};
        return data;
    }
</script>
</body>
</html>